package com.opgea.crm.web.form;

import java.util.ArrayList;
import java.util.List;

import com.opgea.crm.common.util.DateUtil;
import com.opgea.crm.domain.entities.Lead;
import com.opgea.crm.domain.entities.Leademails;
import com.opgea.crm.domain.entities.Leadphones;
import com.opgea.crm.domain.entities.Leadprofile;
import com.opgea.crm.domain.entities.Opportunity;


public class OpportunityForm {
	
	private Long opportunityId;
	private String opportunityTitle;
	private String id;
	private String firstName;
	private String title;
	private String email;
	private String phone1;
	private String phone2;
	private String companyName;
	private String dealSize;
	private String createDate;
	private String targetDate;
	private String actualCloseDate;
	private String opportunityDiscription;
	private String oppSearchCriteria;
	private String criteriaValue;

	//combos
	private String salesPerson;
	private long salesPersonId;
	private String status;
	private long statusId;
	private String stage;
	private long stageId;	
	private String oppStage;
	private long oppStageId;
	private String oppStatus;
	private long oppStatusId;
	private String oppClosingProbability;
	private long oppClosingProbabilityId;
	
	private String oppLeadid;
	
	public Long getOpportunityId() {
		return opportunityId;
	}


	public void setOpportunityId(Long opportunityId) {
		this.opportunityId = opportunityId;
	}


	public String getOpportunityTitle() {
		return opportunityTitle;
	}


	public void setOpportunityTitle(String opportunityTitle) {
		this.opportunityTitle = opportunityTitle;
	}
   
	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}


	public String getFirstName() {
		return firstName;
	}


	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}


	public String getPhone1() {
		return phone1;
	}


	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}


	public String getPhone2() {
		return phone2;
	}


	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}


	public String getCompanyName() {
		return companyName;
	}


	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}


	public String getDealSize() {
		return dealSize;
	}


	public void setDealSize(String dealSize) {
		this.dealSize = dealSize;
	}


	public String getCreateDate() {
		return createDate;
	}


	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}


	public String getTargetDate() {
		return targetDate;
	}


	public void setTargetDate(String targetDate) {
		this.targetDate = targetDate;
	}


	public String getActualCloseDate() {
		return actualCloseDate;
	}


	public void setActualCloseDate(String actualCloseDate) {
		this.actualCloseDate = actualCloseDate;
	}


	public String getOpportunityDiscription() {
		return opportunityDiscription;
	}


	public void setOpportunityDiscription(String opportunityDiscription) {
		this.opportunityDiscription = opportunityDiscription;
	}


	public String getOppSearchCriteria() {
		return oppSearchCriteria;
	}


	public void setOppSearchCriteria(String oppSearchCriteria) {
		this.oppSearchCriteria = oppSearchCriteria;
	}


	public String getCriteriaValue() {
		return criteriaValue;
	}


	public void setCriteriaValue(String criteriaValue) {
		this.criteriaValue = criteriaValue;
	}




	public String getSalesPerson() {
		return salesPerson;
	}


	public void setSalesPerson(String salesPerson) {
		this.salesPerson = salesPerson;
	}


	public long getSalesPersonId() {
		return salesPersonId;
	}


	public void setSalesPersonId(long salesPersonId) {
		this.salesPersonId = salesPersonId;
	}


	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}


	public long getStatusId() {
		return statusId;
	}


	public void setStatusId(long statusId) {
		this.statusId = statusId;
	}


	public String getStage() {
		return stage;
	}


	public void setStage(String stage) {
		this.stage = stage;
	}


	public long getStageId() {
		return stageId;
	}


	public void setStageId(long stageId) {
		this.stageId = stageId;
	}


	public String getOppStage() {
		return oppStage;
	}


	public void setOppStage(String oppStage) {
		this.oppStage = oppStage;
	}


	public long getOppStageId() {
		return oppStageId;
	}


	public void setOppStageId(long oppStageId) {
		this.oppStageId = oppStageId;
	}


	public String getOppStatus() {
		return oppStatus;
	}


	public void setOppStatus(String oppStatus) {
		this.oppStatus = oppStatus;
	}


	public long getOppStatusId() {
		return oppStatusId;
	}


	public void setOppStatusId(long oppStatusId) {
		this.oppStatusId = oppStatusId;
	}


	public String getOppClosingProbability() {
		return oppClosingProbability;
	}


	public void setOppClosingProbability(String oppClosingProbability) {
		this.oppClosingProbability = oppClosingProbability;
	}


	public long getOppClosingProbabilityId() {
		return oppClosingProbabilityId;
	}


	public void setOppClosingProbabilityId(long oppClosingProbabilityId) {
		this.oppClosingProbabilityId = oppClosingProbabilityId;
	}


	public String getOppLeadid() {
		return oppLeadid;
	}


	public void setOppLeadid(String oppLeadid) {
		this.oppLeadid = oppLeadid;
	}


	public OpportunityForm(){}
	
	
	public OpportunityForm(Opportunity opportunity)
	{
	
      Lead lead= opportunity.getRelatedContact();  
      this.setOpportunityId(opportunity.getId());
      this.setId(String.valueOf(lead.getId()));
      this.setTitle(opportunity.getOpportunityTitle());
	  this.setOpportunityTitle(opportunity.getOpportunityTitle());
	  this.setDealSize(Integer.toString(opportunity.getDealSize()));
	  String description = new String(opportunity.getOpportunityDescription());
	  this.setOpportunityDiscription(description);
	  this.setTargetDate(DateUtil.dateToString(opportunity.getForecastClosingDate()));
	  this.setCreateDate(DateUtil.dateToString(opportunity.getCreatedDate()));
	  this.setActualCloseDate(DateUtil.dateToString(opportunity.getActualCloseDate()));
	  
	  if(opportunity.getConfidenceLevel() != null){
		  this.setOppClosingProbability(opportunity.getConfidenceLevel().getFieldValue());
		  this.setOppClosingProbabilityId(opportunity.getConfidenceLevel().getId());
	  }
	  if(opportunity.getStage() != null){
		  this.setStage(opportunity.getStage().getFieldValue());
		  this.setStageId(opportunity.getStage().getId());
	  }
	  if(opportunity.getOpportunityStatus() != null){
		  this.setStatus(opportunity.getOpportunityStatus().getFieldValue());
		  this.setStatusId(opportunity.getOpportunityStatus().getId());
	  }
	  if(lead.getCompany()!=null){
		  this.setCompanyName(lead.getCompany().getName());
	  }
	  if(opportunity.getRelatedContact()!=null){
		  this.setFirstName(opportunity.getRelatedContact().getFirstName());
	  }
      
      Leadprofile profile1 = lead.getLeadprofile();
      if(profile1.getEmployee() != null){
    	  this.setSalesPerson(profile1.getEmployee().getFirstName());
    	  this.setSalesPersonId(profile1.getEmployee().getId());
      }
      
      Leademails email1 = lead.getLeademail();
      this.setEmail(email1.getAddress());
      
	  List<Leadphones> phones = new ArrayList<Leadphones>(lead.getLeadphonesCollection());
		Leadphones phone1 = null;
		Leadphones phone2 = null;
		if(phones.size()>0){
			phone1 = phones.get(0);
			phone2 = phones.get(1);
		}
		
		this.setPhone1(phone1.getPhoneNo());
		this.setPhone2(phone2.getPhoneNo()); 
	}


}
